div {
    width: 400px;
    height: 200px;
    margin: 25px auto;
}

/*使用背景定位实现*/
.div1 {
    background: linear-gradient(to right, red, blue, green);
    background-size: 200%;
    transition: background-position .4s linear;
}
.div1:hover {
    background-position: 100% 0;
}

/*借助background-color属性实现*/
.div2 {
    background: olive linear-gradient(to right, rgba(0, 255, 0, 0), rgba(0, 255, 0, .5));
    transition: background-color .4s;
}
.div2:hover {
    background-color: purple;
}

/* 借助伪元素的透明度实现 */
.div3 {
    background: linear-gradient(to right, olive, green);
    position: relative;
}
.div3::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(to right, green, purple);
    opacity: 0;
    transition: opacity .4s;
}
.div3:hover::before {
    opacity: 1;
}